<template>
  <div>
    <h1>加载图片</h1>
  </div>
</template>

<script setup>
function loadImg(src) {
  return new Promise((resolve, reject) => {
    const img = document.createElement('img')
    img.onload = () => {
      resolve(img)
    }
    img.onerror = () => {
      const err = new Error(`图片加载失败${src}`)
      reject(err)
    }
    img.src = src
  })
}
loadImg('https://img.php.cn/teacher/course/20230704/a84df050801ec6a015a5831d4213cf2c.png').then(res => {
  console.log(res.width)
})
</script>

<style scoped></style>
